package com.xxgc.cloud.error.center.error;

import com.xxgc.cloud.error.center.GlobalException;
import com.xxgc.cloud.error.center.result.ErrResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

import java.sql.SQLSyntaxErrorException;

/**
 * @program: SpringCloudStudy
 * @description: 数据库相关
 * @author: Shijiayi
 * @create: 2022-12-19 19:41
 **/
@Slf4j
@ControllerAdvice
@ResponseBody
public class JdbcException extends GlobalException{

    @ExceptionHandler(value = {SQLSyntaxErrorException.class})
    public ErrResult<SQLSyntaxErrorException> sQLSyntaxErrorException(SQLSyntaxErrorException e){
        log.error(e.toString());
        String msg = active.equals(myActive) ? system : JDBC_SQL_MSG;
        return active.equals(myActive) ? ErrResult.error(msg,JDBC_SQL_CODE) : ErrResult.error(msg,JDBC_SQL_CODE,e);
    }

}
